﻿using System;

namespace ParserGenerator.ScannerConstruction
{
    [Serializable]
    public abstract class ScannerAutomatonItem
    {
        public bool IsShift => this is ScannerAutomatonShift;
        public bool IsReduction => this is ScannerAutomatonReduction;

        public ScannerAutomatonShift AsShift => (ScannerAutomatonShift)this;
        public ScannerAutomatonReduction AsReduction => (ScannerAutomatonReduction)this;

        public int Number { get; }
        public ScannerAutomatonItemSet FollowSet { get; }

        internal ScannerAutomatonItem(int number)
        {
            if (number < 0)
                throw new ArgumentOutOfRangeException(nameof(number), SR.ScannerAutomatonItemNumberMustBeNonNegative);
            Number = number;
            FollowSet = new ScannerAutomatonItemSet();
        }

        public override string ToString()
        {
            return Number + ": " + FollowSet;
        }
    }
}
